﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Web.Management;
using Plugin_Interfaces;

namespace PMKB_Web
{
    public static class SiteUtils
    {
        //app harbor class
        //public  class LogEventAppHarbor : WebRequestErrorEvent
        //{
        //    public LogEventAppHarbor(string message)
        //        : base(null, null, 100001, new Exception(message))
        //    {
        //    }
        //}
        public static Dictionary<string, Type> plugins
        {
            get
            {
                return HttpContext.Current.Application["MVCPlugin"] as Dictionary<string, Type>;
            }
            set
            {
                HttpContext.Current.Application["MVCPlugin"] = value;   
            }
        }

        public static string ConnectionString
        {
            get
            {
                string con = "";
                //TODO: do not replicate this in tests...
                string s = "SQLSERVER_CONNECTION_STRING";
                string val = ConfigurationManager.AppSettings[s];
                if ((!string.IsNullOrEmpty(val)) && (val.ToLower() != "appharbor"))
                {
                    con=val;
                }
                else
                {
                    //if not sql server, default to connection
                    con="name=PMKB";
                }
                //new LogEventAppHarbor("connection is : "+con ).Raise();

                return con;

            }
        }
    }
}